package com.fdb.efp.esb.service.impl.ms;

import com.fdb.efp.esb.common.constant.MsLoanConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.fdb.efp.esb.service.bo.req.MsLoanReq;
import com.fdb.efp.esb.service.bo.resp.MsLoanResp;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.client.impl.MSESBBeanCreator;
import com.fdb.efp.esb.service.facade.MsLoanService;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.basic.framework.core.util.SpringContextUtils;

/**
 * 马上贷款审核通知接口（广州银行->马上）
 * 
 * @author heyingfeng
 * @since 2018年12月18日 下午4:33:36
 * @version 1.0
 */
@Service("msLoanService")
public class MsLoanServiceImpl implements MsLoanService, FrameworkService {

	private static Logger log = LoggerFactory.getLogger(MsLoanServiceImpl.class);

	// 发送请求
	@Override
	public MsLoanResp msLoan(MsLoanReq msLoanReq) throws Exception {
		MsLoanResp msLoanResp = null;
		try {
			msLoanResp = ESBClientFactory.buildClient().withBody(msLoanReq).withTradeNo(MsLoanConstant.TRADE_NO_30220006)
					.withScene(MsLoanConstant.SCENE_01)
					.withESBBeanFactory((MSESBBeanCreator) SpringContextUtils.getBean("MSESBBeanCreator"))
					.create().sendAndReceive().getBody(MsLoanResp.class);
			if(msLoanResp!=null) {
				if (MsLoanConstant.RetCodeEnum.SUCCESS.VALUE.equals(msLoanResp.getRetStCd())) {
					log.info("马上审批结果消费接口调用，成功返回，开始进行后处理 ，请求参数： " + msLoanReq + ", 返回结果： " + msLoanResp);
					return msLoanResp;
				}
			}
			log.error("马上审批结果消费接口调用失败！,返回结果： " + msLoanResp);
			throw new ESBException();
		} catch (Exception e) {
			log.error("马上审批结果消费接口调用失败！"+e.getMessage());
			e.printStackTrace();
			throw e;
		}
	}

}
